//
//  HMMaivViewController.swift
//  HM007
//
//  Created by GD on 17/6/18.
//  Copyright © 2017年 geduo. All rights reserved.
//

import UIKit

class HMMaivViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        UITabBar.appearance().tintColor = UIColor.orange

//        viewControllers = []
        addChildViewController(childViewController: HMHomeTableViewController(), title: "首页", imageName: "tabbar_home", selImage: "tabbar_home")
        addChildViewController(childViewController: HMMessageTableViewController(), title: "消息", imageName: "tabbar_message_center", selImage: "tabbar_home")
        addChildViewController(childViewController: HMDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover", selImage: "tabbar_discover")
        addChildViewController(childViewController: HMProfileTableViewController(), title: "个人", imageName: "allproducts", selImage: "allproducts_selected")
    }

    //重载
    func addChildViewController(childViewController:UIViewController,title:String,imageName:String, selImage:String){
        childViewController.tabBarItem.image = UIImage(named: imageName)
       
        
        if title == "我的" {
            //如何调整tabBar中Image的大小和位置.
            childViewController.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0)
        }else{
        
            childViewController.title = title
        }
        
        
        //如何设置tabbar中的字体大小和颜色?
        childViewController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.brown], for: .normal)
        childViewController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 19)], for: .normal)
        
        childViewController.tabBarItem.selectedImage = UIImage(named: selImage)
        
        let nav = UINavigationController(rootViewController: childViewController)
        
        addChildViewController(nav)
    }
    
}
